<?php
include_once("isLogin.php")
?>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>用户列表</title>
</head>
<body>
<form action="list.php" method="POST">
  <div class="sel">
    <input type="text" name="sel" placeholder="请输入查找的用户名"><input type="submit" value="查找" name="button">  <span class="out">欢迎:<?=$_SESSION["user"]?>&nbsp;&nbsp;<input type="submit" value="退出" name="out"></span>
  </div>
</form>
<table>
  <caption><b>管理员信息列表</b></caption>
  <!--表头-->
  <tr>
    <th>id</th>
    <th>username</th>
    <th>password</th>
    <td>操作</td>
  </tr>
  <?php
    include_once("conn.php");
    if($_POST["out"]!=""){
      session_destroy();
      echo '<script>window.location.href="login.html";</script>';
    }
    if($_POST["button"]=="" || $_POST["sel"]==""){
      $sql = "select * from users order by id desc";
    }else{
      $sql = "select * from users where username like '%".$_POST["sel"]."%'";
    }
    $result = mysqli_query($conn,$sql);
    while($myrow = mysqli_fetch_assoc($result))//从结果集一行行读出记录
    {
  ?>
  <tr>
    <td><?=$myrow["id"]?></td>
    <td><?=$myrow["username"]?></td>
    <td><?=$myrow["password"]?></td>
    <td><a href="edit.php?id=<?=$myrow['id']?>">修改</a> | <a href="delaction.php?id=<?=$myrow['id']?>" onclick="return confirm('你确定要删除嘛，不能恢复噢！')">删除</a></td>
  </tr>
  <?php
    }
  ?>
</table>
</body>
<style>
table{
  margin: 0 auto;
  border-collapse: collapse;
}
th,td{
  border: 1px solid #000;
  text-align: center;
  width: 120px;
  height: 40px;
}
.sel{
  margin: 10px 390px;
}
.out{
  margin-left: 125px;
}
a{
  text-decoration:none; 
  color: #000;
}

</style>
</html>